﻿
var mStockBillType; //单据类型
var mStockBill = {};//物品记录对象
var mStockDetails = [];
var mStockBill_User; //当前用户

var mStockDetailDlg; //物品明晰对话框

var mCaseFileQuery = {};

var mStockBill_SelectURL; //选择上游单据的页面

var mStockBill_Query_Dlg; //选择上游单据的对话框

var mStockBill_SelectResultId = 0;//选择上游单据的返回的Id;

var mDlgAttachment;//附件窗口

var mEviBillEstimate;//存放物品单据的审核时间，用于显示预计扣押到期时间

$(function () {
    try {
        $('#stockBillDiv').mask('正在加载单据...');
        extendEasyUI();

        var args = getUrlArgs();

        mStockBillType = parseInt(args["billType"]);
        var stockBillId = parseInt(args["stockBillId"]);

        setRelateBillType();
        setBillTypeFeature();

        mStockBill_User = gGetLoginUser();//获取当前登录用户

        $('#detailDataGrid').datagrid({
            fitColumns: true,
            rownumbers: true,
            resizable: true,
            pagination: false,
            nowrap: false,
            height: 180,
            idField: 'Id',
            singleSelect: true,
            onDblClickRow: viewStockDetail,
            toolbar: "#stockDetailToolBar",
            columns: [[
                   { title: 'Id', field: 'Id', align: 'left', width: 5, hidden: true },
                   {
                       title: '类型', field: 'EvidenceType', align: 'left', width: 120, formatter:
                         function (value, rowData, index) {
                             return rowData.Evidence.EvidenceType.Name;
                         }
                   },
                   {
                       title: '名称', field: 'Name', align: 'left', width: 120, formatter:
                         function (value, rowData, index) {
                             return rowData.Evidence.Name;
                         }
                   },
                   {
                       title: '型号', field: 'Model', align: 'left', width: 120, formatter:
                         function (value, rowData, index) {
                             return rowData.Evidence.Model;
                         }
                   },
                   { title: '数量', field: 'Qty', align: 'left', width: 80 },
                   { title: '金额', field: 'Amount', align: 'left', width: 100 },
                   {
                       title: '仓位', field: 'Storage', align: 'left', width: 220,
                       formatter:
                           function (value, rowData, index) {
                               return rowData.Storage ? rowData.Storage.FullName : null;
                           }
                   }
                   //{ title: '扣押来源', field: 'Origin', align: 'left', width: 100, formatter: function (value, rowData, index) { return rowData.Evidence.OwnerName; } }
            ]]
        });

        $("#cmbTransferDept").combobox({
            valueField: 'Id',
            textField: 'Name',
            editable: false,
            panelWidth: 200,
            onSelect: selTransferDept
        });

        $("#cmbCaseCategory").combobox({
            valueField: 'Id',
            textField: 'Name',
            panelHeight: "auto",
            onSelect: function (record) { mStockBill.Category = record; }
        });

        //$("#cmbTransfer").combobox({
        //    valueField: 'Id',
        //    textField: 'Name',
        //    onSelect: function (record) { mStockBill.Transfer = record; }
        //});

        $('#cmbManageDept').combobox({
            valueField: 'Id',
            textField: 'Name',
            panelHeight: 160,
            panelWidth: 200,
            formatter: function (row) { return gFormatDeptName(row.Name); },
            onSelect: onManageDeptSelected //设置管理部门
        });

        $("#cmbStockType").combobox({
            valueField: 'Id',
            textField: 'Name',
            panelHeight: "auto",
            formatter: function (row) { return gFormatDeptName(row.Name); },
            onSelect: function (record) { mStockBill.StockType = record; }
        });

        initStockBill(stockBillId);

        loadBaseData();


        //loadTransfers(mStockBill.TransferDept.Id); 

        display();

        //setRelateBillType();



        $('#caseFileDataGrid').datagrid({
            url: '/Case/LoadCaseFileSimpleList',
            fitColumns: true,
            rownumbers: true,
            resizable: true,
            pagination: true,
            pageNumber: 1,
            pageSize: 20,
            nowrap: false,
            idField: 'Id',
            toolbar: '#caseFileToolbar',
            queryParams: { 'caseFileQuery': JSON.stringify(buildCaseFileQuery()) },
            singleSelect: true,
            
            columns: [[
                   { title: 'Id', field: 'Id', align: 'left', width: 10, hidden: true },
                   { title: '文件名', field: 'FileName', align: 'left', width: 150 },
                   { title: '日期', field: 'UploadTime', align: 'left', width: 80, formatter: formatDate },
                   { title: '文件大小', field: 'Size', align: 'left', width: 80 }
            ]]
        });
        $('#stockBillDiv').unmask();
    } catch (ex) {
        alert('错误提示:' + ex);
        $('#stockBillDiv').unmask();
    }
});

//选择办案单位
function selTransferDept(record) {

    if (record) {
        mStockBill.TransferDept = record;
        //loadTransfers(record.Id);
    }
}

function setBillTypeFeature() {
    $('#billTypeName').text(gGetBillTypeName(mStockBillType));

    if (mStockBillType == 2 || mStockBillType == 4) {
        $('#lblTransferDept').text("办案单位");
        $('#lblTransfer').text("办案人");
    } else if (mStockBillType == 3 || mStockBillType == 5) {
        $('#lblTransferDept').text("调用单位");
        $('#lblTransfer').text("调用人");
    }

}

//设置按钮文本，和url
function setRelateBillType() {
    if (mStockBillType == 2 || mStockBillType == 4 || mStockBillType == 5) {
        $('#btnSelectSource').html("<span class='l-btn-left'><span class='l-btn-text icon-newspaper l-btn-icon-left'>选择物品记录单</span></span>");
        mStockBill_SelectURL = '/Case/EvidenceBillListView?modeType=1&targetBillType=' + mStockBillType;
    } else if (mStockBillType == 3) {
        $('#btnSelectSource').html("<span class='l-btn-left'><span class='l-btn-text icon-newspaper l-btn-icon-left'>选择调查出库单</span></span>");
        mStockBill_SelectURL = '/Case/StockBillListView?modeType=1&billType=5&targetBillType=3';
    }
}

function caseFileDiscription() {

}

function formatDate(value, rowData, index) {
    if (value) {
        return gFormatDateFormCSharp(value, 'yyyy-MM-dd');
    }
}

function FormmatName(value, rowData, index) {
    return '<span><a  href="javascript:void(0);"  onclick="function()ClickFunction(' + rowData.Id + ')" sty>' + value + '</a></span>';
}

function buildCaseFileQuery() {
    var query = {};
    query.BillType = 1;
    query.BillId = mStockBill.Id;

    return query;
}

//初始化当前单据
function initStockBill(stockBillId) {
    if (stockBillId == 0) {
        mStockBill.Id = 0; //新增
        mStockBill.BillType = mStockBillType; //单据类型
        mStockBill.BillTime = gGetCurrentTime();
        mStockBill.Department = mStockBill_User.Department;
        //mStockBill.TransferDept = mStockBill_User.Department; //默认等于制单部门
        //mStockBill.Transfer = mStockBill_User;                //默认等于制单人
        mStockBill.Preparer = mStockBill_User;
        loadBillSerialNo();
    } else {
        loadStockBill(stockBillId);
    }
}

//读取单据信息
function loadStockBill(billId) {
    $.ajax({
        url: "/Case/LoadStockBill",
        type: "POST",
        dataType: "json",
        async: false,
        data: { "stockBillId": billId },
        success: function (req) {
            if (req.IsSuccess) {
                mStockBill = JSON.parse(req.Bill);
                mStockDetails = JSON.parse(req.Details);
                mEviBillEstimate = mStockBill.CheckTime;
            }
        },
    });
}
//显示物品明细
function loadDetails() {
    $('#detailDataGrid').datagrid('loadData', mStockDetails);
}

function lockTransferWithBillType() {
    if (mStockBillType == 2 || mStockBillType == 3 || mStockBillType == 4) {
        $('#cmbTransferDept').combobox("disable");
        $('#cmbTransfer').combobox("disable");
    } else if (mStockBillType == 5) {
        $('#cmbTransferDept').combobox("enable");
        $('#cmbTransfer').combobox("enable");
    }
}

function loadSourceBillBySerialNo(serialNo) {
    $.ajax({
        url: "/Case/LoadBillBySerialNo",
        type: "POST",
        dataType: "json",
        async: false,
        data: { "serialNo": serialNo },
        success: function (req) {
            if (req.IsSuccess) {

                var result = req.Data;

                var isSuccess = false;

                if (result.CaseId) {

                    if (result.ManageDeptId != mStockBill_User.Department.Id) {
                        $.messager.alert('提示', '源单据保管部门必须等于当前部门!');
                        $('#txtSourceSerialNo').val('');
                    }

                    if (mStockBillType == 2 && result.BillType == 1) {
                        isSuccess = true;
                    } else if (mStockBillType == 3 && result.BillType == 5) {
                        isSuccess = true;
                    } else if (mStockBillType == 4 && (result.BillType == 1 || result.BillType == 2 || result.BillType == 3 || result.BillType == 5)) {
                        isSuccess = true;
                    } else if (mStockBillType == 5 && (result.BillType == 1 || result.BillType == 2 || result.BillType == 3 || result.BillType == 4)) {
                        isSuccess = true;
                    } else {
                        $.messager.alert('提示', '源单据类型与当前单据类型不匹配!');
                        $('#txtSourceSerialNo').val('');
                    }

                    if (isSuccess) {
                        onSelectSourceBill(result.BillType, result.BillId);
                    }

                } else {
                    $.messager.alert('提示', '没有找到源单据: ' + serialNo + " !");
                    $('#txtSourceSerialNo').val('');
                }


            }
        },
    });
}

//显示出入库单据
function display() {
    try {

        lockTransferWithBillType();

        lockElements(mStockBill.IsCheck);

        $('#txtNumber').val(mStockBill.Number);
        $('#txtSerialNo').val(mStockBill.SerialNo);
        $('#txtSourceSerialNo').val(mStockBill.SourceSerialNo);

        if (mStockBill.Category) {
            $("#cmbCaseCategory").combobox("select", mStockBill.Category.Id);
        }
        if (mStockBill.TransferDept) {
            $("#cmbTransferDept").combobox("select", mStockBill.TransferDept.Id);
            //loadTransfers(mStockBill.TransferDept.Id)
        }
        $("#txtTransferName").val(mStockBill.TransferName);

        $('#txtTransferPhone').val(mStockBill.TransferPhone);
        $('#txtDescription').val(mStockBill.Description);
        if (mStockBill.ManageDept) {
            $("#cmbManageDept").combobox("select", mStockBill.ManageDept.Id);
        }
        if (mStockBill.Department) {
            $("#txtDepartment").val(gFormatDeptName(mStockBill.Department.Name));
        }
        if (mStockBill.Preparer) {
            $("#txtPreparer").val(mStockBill.Preparer.Name);
        }
        $("#txtBillTime").val(gFormatDateFormCSharp(mStockBill.BillTime));

        if (mStockBill.StockType) {
            $("#cmbStockType").combobox("select", mStockBill.StockType.Id);
        }

        if (mStockBill.CheckDept) {
            $("#txtCheckDept").val(gFormatDeptName(mStockBill.CheckDept.Name));
        }

        if (mStockBill.Checker) {
            $("#txtChecker").val(mStockBill.Checker.Name);
        }

        if (mStockBill.CheckTime) {
            $("#txtCheckTime").val(gFormatDateFormCSharp(mStockBill.CheckTime));
        }



        loadDetails();

    } catch (ex) {
        alert("display:  " + ex);
    }
}


function lockElements(lock) {
    if (lock) {
        $('#txtSourceSerialNo').attr("disabled", true);
        $('#txtNumber').attr("disabled", true);
        $('#txtSourceSerialNo').attr("disabled", true);
        $('#cmbCaseCategory').combobox("disable");
        $('#cmbTransferDept').combobox("disable");
        $('#cmbStockType').combobox("disable");
        $('#txtTransferName').attr("disabled", true);
        $('#txtTransferPhone').attr("disabled", true);
        $('#txtDescription').attr("disabled", true);

        $('#btnSaveBill').hide();
        $('#btnSelectSource').hide();
        $('#btnConfirm').hide();
        $('#btnDelStockDetail').hide();
    }
}

function onManageDeptSelected(record) {
    mStockBill.ManageDept = record;
}
//读取所有基本数据类型
function loadBaseData(user) {
    gLoadAllDepts(function (orgs) {
        $('#cmbTransferDept').combobox("loadData", orgs);
        $('#cmbManageDept').combobox("loadData", orgs);
    });
    gLoadAllCaseCategories(function (ccs) { $('#cmbCaseCategory').combobox("loadData", ccs); });

    var stockTypes = gLoadStockTypes(mStockBillType);
    if (stockTypes)
        $('#cmbStockType').combobox("loadData", stockTypes);
}

//读取送交人
//function loadTransfers(deptId) {
//    var users = gLoadUserListByDeptId(deptId);
//    $('#cmbTransfer').combobox('loadData', users);

//    if (mStockBill.Transfer && mStockBill.Transfer.Department && mStockBill.Transfer.Department.Id == mStockBill.TransferDept.Id) {
//        $('#cmbTransfer').combobox('select', mStockBill.Transfer.Id);
//    } else {
//        mStockBill.Transfer = null;
//        $("#cmbTransfer").combobox("setValue", "");
//    }
//}

function onStockTypeSelected(record) {
    mStockBill.StockType = record;
}

//保存物品单据
function saveStockBillAction() {
    try {

        if (mStockBill.IsCheck) {
            $.messager.alert('提示', '单据已经审核，不能再保存!');
            return;
        }

        $('#stockBillDiv').mask('正在保存单据...');

        //mStockBill.Number = $('#txtNumber').val();
        mStockBill.TransferPhone = $('#txtTransferPhone').val();
        mStockBill.Description = $('#txtDescription').val();

        if (checkStockBill()) {
            var json = JSON.stringify(mStockBill);
            var details = JSON.stringify(mStockDetails);
            var oldSerialNo = mStockBill.SerialNo;

            $.ajax({
                url: "/Case/SaveStockBill",
                type: "POST",
                dataType: "json",
                data: { "stockBillJson": json, "detailsJson": details },
                async: false,
                success: function (req) {
                    if (req.IsSuccess) {
                        loadStockBill(req.Data);
                        display();

                        if (oldSerialNo != mStockBill.SerialNo)
                            $.messager.alert('提示', '保存成功,单据号更新为: ' + mStockBill.SerialNo);
                        else
                            $.messager.alert('提示', '保存成功');
                    } else {
                        $.messager.alert('提示', '保存失败!' + req.Data, "warning");
                    }
                    $('#stockBillDiv').unmask();
                },

            });
        }
    } catch (ex) {
        $.messager.alert('提示', ex, "warning");
    } finally {
        $('#stockBillDiv').unmask();
    }
}

//检查物品单据
function checkStockBill() {
    if (!mStockBill.Number) {
        $.messager.alert('提示', '请录入案件编号!', "warning");
        return false;
    }

    if (!mStockBill.Category) {
        $.messager.alert('提示', '请选择案件类型!', "warning");
        return false;
    }

    if (!mStockBill.TransferDept) {
        $.messager.alert('提示', '请选择办案单位!', "warning");
        return false;
    }

    if (mStockBill.TransferName == undefined || mStockBill.TransferName == '' || mStockBill.TransferName == null) {
        $.messager.alert('提示', '请选择办案人!', "warning");
        return false;
    }

    if (!mStockBill.StockType) {
        $.messager.alert('提示', '请选择出入库类型!', "warning");
        return false;
    }
    var count = mStockDetails.length;

    for (var i = 0; i < count; i++) {
        var detail = mStockDetails[i];

        if (!detail.Storage) {
            $.messager.alert('提示', '请选择仓位!', "warning");
            return false;
        }

        if (detail.Qty < detail.minQty || detail.Qty > detail.maxQty) {
            $.messager.alert('提示', "请输入正确的数量!");
            return false;
        }
    }

    return true;
}

//选择物品单据
function selectSourceAction() {

    try {
        var title = $('#btnSelectSource').text();

        mStockBill_SelectResultId = 0;

        mStockBill_Query_Dlg = art.dialog({
            title: title,
            content: "<iframe scrolling='yes' frameborder='0' src='" + mStockBill_SelectURL + "' style='width:750px;height:470px;'/>",
            lock: true,
            initFn: function () {
            }
        });

    } catch (ex) {
        alert(ex);
    }
}

function loadBillSerialNo() {
    $.ajax({
        url: '/Case/LoadNextBillSerialNo',
        type: "POST",
        dataType: "json",
        async: false,
        data: { "billType": mStockBillType },
        success: function (req) {
            if (req.IsSuccess) {
                mStockBill.SerialNo = req.Data;
            }
        },
    });
}

//选择原单
function onSelectSourceBill(sourceType, billId) {

    if (sourceType == 1){
        selectEvidenceBill(billId);
    }
    else if (sourceType == 2 && mStockBillType == 5) {
        selectStockBill(billId, sourceType);
    }
    else if (sourceType == 5 ) {
        selectInquiryOutStockBill(billId);
    }
        

    display();
}
//选择物品单据
function selectEvidenceBill(billId) {
    var url = "/Case/LoadEvidenceBill";

    var bill;
    var details;
    $.ajax({
        url: url,
        type: "POST",
        dataType: "json",
        async: false,
        data: { "evidenceBillId": billId },
        success: function (req) {
            if (req.IsSuccess) {
                bill = JSON.parse(req.Bill);
                details = JSON.parse(req.Details);
                mEviBillEstimate = bill.CheckTime;
            }
        },
    });
    mStockBill.BillType = mStockBillType;
    mStockBill.SourceBillType = 1;
    mStockBill.CaseId = bill.Id;
    mStockBill.SourceBillId = bill.Id;
    mStockBill.SourceSerialNo = bill.SerialNo;
    mStockBill.Category = bill.Category;//案件类型

    mStockBill.TransferDept = bill.TransferDept;
    mStockBill.TransferName = bill.TransferName;
    mStockBill.TransferPhone = bill.TransferPhone;

    mStockBill.Department = mStockBill_User.Department;
    mStockBill.Preparer = mStockBill_User;
    mStockBill.Number = bill.Number;
    mStockBill.ManageDept = bill.ManageDept;
    mStockBill.BillTime = gGetCurrentTime();

    var detailCount = details.length;
    mStockDetails = [];

    for (var i = 0; i < detailCount; i++) {
        var evidenceDetail = details[i];
        var stockDetail = {};

        //stockDetail.Id = 0;
        stockDetail.Evidence = evidenceDetail;

        switch (mStockBillType) {
            case 2:
                stockDetail.minQty = evidenceDetail.StockQty * -1;
                stockDetail.maxQty = evidenceDetail.Qty - evidenceDetail.StockQty;
                break;
            case 4:
                stockDetail.minQty = evidenceDetail.OutStockQty * -1;
                stockDetail.maxQty = evidenceDetail.StockQty;
            case 5:
                stockDetail.minQty = evidenceDetail.InquiryOutStockQty * -1;
                stockDetail.maxQty = evidenceDetail.StockQty;

        }

        stockDetail.Qty = stockDetail.maxQty; //默认等于最大
        stockDetail.Amount = stockDetail.Qty * evidenceDetail.Price;

        if (stockDetail.Qty > 0) //物品单的明细数量要大于0才能入库。
            mStockDetails.push(stockDetail);
    }
}

function selectStockBill(billId,sourceType)
{
    var url = "/Case/LoadStockBill";

    var bill;
    var details;

    $.ajax({
        url: url,
        type: "POST",
        dataType: "json",
        async: false,
        data: { "stockBillId": billId },
        success: function (req) {
            if (req.IsSuccess) {
                bill = JSON.parse(req.Bill);
                details = JSON.parse(req.Details);
                mEviBillEstimate = bill.CheckTime;
            }
        },
    });
    mStockBill.BillType = mStockBillType;
    mStockBill.SourceBillType = sourceType; 
    mStockBill.SourceBillId = bill.Id;
    mStockBill.SourceSerialNo = bill.SerialNo;
    mStockBill.CaseId = bill.CaseId;
    mStockBill.Category = bill.Category;//案件类型
    mStockBill.TransferDept = bill.TransferDept;
    mStockBill.TransferName = bill.TransferName;
    mStockBill.Department = mStockBill_User.Department;
    mStockBill.Preparer = mStockBill_User;
    mStockBill.Number = bill.Number;
    mStockBill.ManageDept = bill.ManageDept;
    mStockBill.BillTime = gGetCurrentTime();

    var detailCount = details.length;
    mStockDetails = [];

    for (var i = 0; i < detailCount; i++) {
        var orgDetail = details[i];
        var stockDetail = {};

        //stockDetail.Id = 0;
        stockDetail.Evidence = orgDetail.Evidence;
        stockDetail.Qty = orgDetail.Qty - orgDetail.VerificationQty;
        stockDetail.Amount = stockDetail.Qty * orgDetail.Evidence.Price;

        stockDetail.minQty = (orgDetail.Qty - orgDetail.VerificationQty) * -1;
        stockDetail.maxQty = orgDetail.Qty - orgDetail.VerificationQty;

        if (stockDetail.Qty > 0) //物品单的明细数量要大于0才能出入库。
            mStockDetails.push(stockDetail);
    }
}

//选择调用出库单据
function selectInquiryOutStockBill(billId) {
    var url = "/Case/LoadStockBill";

    var bill;
    var details;

    $.ajax({
        url: url,
        type: "POST",
        dataType: "json",
        async: false,
        data: { "stockBillId": billId },
        success: function (req) {
            if (req.IsSuccess) {
                bill = JSON.parse(req.Bill);
                details = JSON.parse(req.Details);
                mEviBillEstimate = bill.CheckTime;
            }
        },
    });
    mStockBill.BillType = mStockBillType;
    mStockBill.SourceBillType = 5;  //调用出库单
    mStockBill.SourceBillId = bill.Id;
    mStockBill.SourceSerialNo = bill.SerialNo;
    mStockBill.CaseId = bill.CaseId;
    mStockBill.Category = bill.Category;//案件类型
    mStockBill.TransferDept = bill.TransferDept;
    mStockBill.TransferName = bill.TransferName;
    mStockBill.Department = mStockBill_User.Department;
    mStockBill.Preparer = mStockBill_User;
    mStockBill.Number = bill.Number;
    mStockBill.ManageDept = bill.ManageDept;
    mStockBill.BillTime = gGetCurrentTime();

    var detailCount = details.length;
    mStockDetails = [];

    for (var i = 0; i < detailCount; i++) {
        var orgDetail = details[i];
        var stockDetail = {};

        //stockDetail.Id = 0;
        stockDetail.Evidence = orgDetail.Evidence;
        stockDetail.Qty = orgDetail.Qty - orgDetail.VerificationQty;
        stockDetail.Amount = stockDetail.Qty * orgDetail.Evidence.Price;

        stockDetail.minQty = (orgDetail.Qty - orgDetail.VerificationQty) * -1;
        stockDetail.maxQty = orgDetail.Qty - orgDetail.VerificationQty;

        if (stockDetail.Qty > 0) //物品单的明细数量要大于0才能入库。
            mStockDetails.push(stockDetail);
    }
}

function viewStockDetail() {
    editStockDetailAction();
}

//编辑出/入库明细
function editStockDetailAction() {

    var row = $('#detailDataGrid').datagrid('getSelected');

    if (row) {
        var index = $('#detailDataGrid').datagrid('getRowIndex', row);
        showStockDetailView(index);
    } else {
        $.messager.alert('提示', '请选择需要查看明细!');
    }
}

//删除物品
function delStockDetailAction() {
    var row = $('#detailDataGrid').datagrid('getSelected');
    if (row) {
        var index = $('#detailDataGrid').datagrid('getRowIndex', row);

        mStockDetails.splice(index, 1);

        loadDetails();

    } else {
        $.messager.alert('提示', '请选择需要查看的明细!');
    }
}
//显示物品子页面
function showStockDetailView(index) {
    try {
        var cTime;
        if (mEviBillEstimate == undefined) {
            var nt = new Date();
            cTime = nt.getTime();
        } else {
            cTime = eval('new ' + mEviBillEstimate.substring(1, mEviBillEstimate.length - 1)).getTime();
        }
        mStockDetailDlg = art.dialog({
            title: '出入库详细信息',
            content: "<iframe scrolling='no' frameborder='0' src='/Case/StockDetailView?index=" + index + "&mBillType=" + mStockBillType + "&mEviBillEstimate=" + cTime + "' style='width:580px;height:410px;'/>",
            lock: true,
            initFn: function () {
            }
        });

    } catch (ex) {
        alert(ex);
    }
}

function checkBillAction() {
    try {
        if (mStockBill.Id == undefined || mStockBill.Id == 0) {
            $.messager.alert('提示', '请先保存单据!');
        } else if (mStockBill.IsCheck) {
            $.messager.alert('提示', '单据已经审核过!');
        } else {
            $('#stockBillDiv').mask('正在审核单据...');
            $.ajax({
                url: "/Case/CheckStockBill",
                type: "POST",
                async: false,
                dataType: "json",
                data: { "checkDeptId": mStockBill_User.Department.Id, "checkerId": mStockBill_User.Id, "billId": mStockBill.Id },
                success: function (req) {
                    if (req.IsSuccess) {
                        loadStockBill(mStockBill.Id);
                        display();
                        $.messager.alert('提示', '审核成功!');
                    } else {
                        $.messager.alert('提示', req.Data, "warning");
                    }
                    $('#stockBillDiv').unmask();
                },
            });
        }

    } catch (ex) {

    } finally {
        $('#stockBillDiv').unmask();
    }
}

//打印库存单据
function printsBillAction() {
    try {
        if (mStockBill.Id == undefined || mStockBill.Id == 0) {
            $.messager.alert('提示', '请先保存单据!');
            return;
        }
        if (!mStockBill.IsCheck) { 
            $.messager.alert('提示', '通过审核之后的单据才能打印!');
            return;
        }
        window.open("/PrintBill/StockBillPage?StockBillId=" + mStockBill.Id + "&mStockBillType=" + mStockBillType, 'newwindow', 'height=768, width=1024, top=0,left=0,  scrollbars=no, resizable=no,location=no, status=no');
    } catch (ex) {

    } finally {
        $('#stockBillDiv').unmask();
    }
};
function exit() {
    parent.art.dialog.list['diaforstokcbillView'].close();
}

function loadCaseFile() {
    try {
        mStockDetailDlg = art.dialog({
            title: '附件',
            content: "<iframe scrolling='yes' frameborder='0' src='/Case/CaseFileListView' style='width:560px;height:360px;'/>",
            lock: true,
            initFn: function () {
            }
        });
    } catch (ex) {
        alert(ex);
    }
}

function addFileAction() {
    $('#fileInput').uploadify('upload', '*');
}

function attachmentAction() {
    if (mStockBill.Id == 0) {
        $.messager.alert('提示', '请先保存单据,再添加附件!');
        return;
    } else {
        mDlgAttachment = art.dialog({
            title: '附件管理',
            id: "dlgAttachment",
            content: "<iframe scrolling='yes' frameborder='0' src='/Attachment/AttachmentView?CaseId=" + mStockBill.CaseId + "&billType=" + mStockBillType + "&billId=" + mStockBill.Id + "' style='width:560px;height:360px;'/>",
            lock: true,
            initFn: function () {
            }
        });
    }
}

function onSourceSerialNoKeyDown(e) {
    if (e.keyCode == 13) {
        var serialNo = $('#txtSourceSerialNo').val();
        if (serialNo != mStockBill.SourceSerialNo) {
            loadSourceBillBySerialNo(serialNo);
        }
    }
}

function printBarCodeAction() {
    var row = $('#detailDataGrid').datagrid('getSelected');
    if (!row) {
        $.messager.alert('提示', '请选择需要打印条码的物品!');
        return;
    }
    var TSCObj;
    TSCObj = new ActiveXObject("TSCActiveX.TSCLIB");
    //TSCObj.ActiveXabout();

    TSCObj.ActiveXopenport("TSC TTP-243E Pro");
    TSCObj.ActiveXsetup("80", "40", "5", "8", "0", "2", "0");
    TSCObj.ActiveXformfeed();
    TSCObj.ActiveXnobackfeed();
    TSCObj.ActiveXsendcommand("SET TEAR ON");
    TSCObj.ActiveXclearbuffer();
    TSCObj.ActiveXbarcode("100", "20", "128", "90", "1", "0", "2", "2", mStockBill.SerialNo);
    TSCObj.ActiveXwindowsfont(100, 160, 40, 0, 2, 0, "微软雅黑", "案件编号：" + mStockBill.Number);
    TSCObj.ActiveXwindowsfont(100, 200, 40, 0, 2, 0, "微软雅黑", "物品名称：" + row.Evidence.Name);
    TSCObj.ActiveXwindowsfont(100, 240, 40, 0, 2, 0, "微软雅黑", "物品数量：" + row.Qty);
    TSCObj.ActiveXprintlabel("3", "1");
    TSCObj.ActiveXcloseport();
}